//
//  XMSModelTransformform.h
//  
//
//  Created by wjxfhxy on 16/4/14.
//
//

#import <Foundation/Foundation.h>

#import "XMSStringKv.h"

typedef NS_ENUM(NSUInteger,XMSModelTransformOpType)
{
    XMSModelTransformOpTypeDBPrimaryKey = 1,
    XMSModelTransformOpTypeDBInsert = 2,
    XMSModelTransformOpTypeDBUpdate = 4,
    XMSModelTransformOpTypeDBInsertOrUpdate = XMSModelTransformOpTypeDBInsert | XMSModelTransformOpTypeDBUpdate,
    XMSModelTransformOpTypeDBDelete = 8,
    XMSModelTransformOpTypeDBSelectList = 16,
    XMSModelTransformOpTypeDBSelectDetail = 32,
    
    XMSModelTransformOpTypeDBSelectJoin = 64,
    
    XMSModelTransformOpTypeDBSelect = XMSModelTransformOpTypeDBSelectList | XMSModelTransformOpTypeDBSelectDetail,
    
//    XMSModelTransformOpTypeDBAll = XMSModelTransformOpTypeDBInsertOrUpdate | XMSModelTransformOpTypeDBDelete | XMSModelTransformOpTypeDBSelect,
    
    XMSModelTransformOpTypeNetList = 128,
    XMSModelTransformOpTypeNetDetail = 256,
    
 //   XMSModelTransformOpTypeNetMix = 512,
    
    XMSModelTransformOpTypeNetAll = XMSModelTransformOpTypeNetList | XMSModelTransformOpTypeNetDetail,
    
//    XMSModelTransformOpTypeAll = XMSModelTransformOpTypeDBAll | XMSModelTransformOpTypeNetAll,
    
    XMSModelTransformOpTypeCommon1 = XMSModelTransformOpTypeDBSelect|XMSModelTransformOpTypeDBInsertOrUpdate|XMSModelTransformOpTypeNetAll,
    
    XMSModelTransformOpTypeOther = INT_MAX
};

@interface XMSModelTransformPair : XMSStringKv
{
    ENSObjectPropertyType _propertyType;
    NSUInteger _opType;
}

@property(nonatomic, assign) ENSObjectPropertyType propertyType;
@property(nonatomic, assign) NSUInteger opType;

@end

@class XMSModelTransformform;

@interface XMSModelTransform : NSObject

+(void)register;

+(void)registerModelTransformOperationKeyType:(void(^)(NSString *key,NSString *property,NSUInteger opType))block;

+(NSString*)modelIdentificationKey;

-(XMSQueueDictionary*)modelTransformValueForOperateType:(XMSModelTransformOpType)opType;

-(XMSQueueDictionary*)modelTransformValueForOperationKeys:(NSArray*)operationKeys;

+(XMSQueueDictionary*)modelTransformForOperationType:(XMSModelTransformOpType)opType;

+(XMSQueueDictionary*)modelTransformForOperationKeys:(NSArray*)operationKeys;

@end

@interface NSArray (JSONArrayTransform)

-(NSArray*)JSONArrayTransformToObjArray:(Class)cls;

-(NSArray*)JSONArrayTransformToObjArray:(Class)cls accordingToKeys:(NSArray*)keys;

-(NSArray*)JSONArrayTransformToObjArray:(Class)cls complexType:(id (^)(NSString *key, ENSObjectPropertyType propertyType, id value))complexType;

-(NSArray*)JSONArrayTransformToObjArray:(Class)cls accordingToKeys:(NSArray*)keys complexType:(id (^)(NSString *key, ENSObjectPropertyType propertyType, id value))complexType;

@end

@interface NSDictionary (JSONDictionaryTransform)

-(id)JSONDictionaryTransformToObj:(Class)cls;

-(id)JSONDictionaryTransformToObj:(Class)cls accordingToKeys:(NSArray*)keys;

-(id)JSONDictionaryTransformToObj:(Class)cls complexType:(id (^)(NSString *key, ENSObjectPropertyType propertyType, id value))complexType;

-(id)JSONDictionaryTransformToObj:(Class)cls accordingToKeys:(NSArray*)keys complexType:(id (^)(NSString *key, ENSObjectPropertyType propertyType, id value))complexType;

@end
